package com.wtcrazy.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtcrazy.dao.ArticleMapper;
import com.wtcrazy.entity.Article;
import com.wtcrazy.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Boolean saveArticle(Article article) {
        if (article.getId() == null) {
            article.setId(UUID.randomUUID().toString().replace("-", ""));
            article.setTime(new Date().getTime());
            return save(article);
        } else {
            return updateById(article);
        }

    }

    @Override
    public String deleteArticle(String id) {
        articleMapper.deleteArticle(id);
        return "删除成功";
    }
}
